Add vendor-agnostic wgpu compute backend#44
Open
naitikpahwa18 wants to merge 5 commits intoIOES-Lab:ros2from
Open
Add vendor-agnostic wgpu compute backend#44naitikpahwa18 wants to merge 5 commits intoIOES-Lab:ros2from
naitikpahwa18 wants to merge 5 commits intoIOES-Lab:ros2from
Conversation
Signed-off-by: Naitik Pahwa <naitikpahwa11@gmail.com>
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull request overview
This PR replaces the CUDA-dependent multibeam sonar compute pipeline with a modular backend architecture. A WGPU-based GPU backend (using Rust + WGSL shaders) and a CPU reference backend are introduced, selectable at runtime via the DAVE_SONAR_COMPUTE_BACKEND environment variable. The sonar sensor is refactored to use a ComputeBackend interface, and computation is moved to a background thread to avoid blocking the rendering pipeline.
Changes:
- New
ComputeBackendabstraction with WGPU (GPU via WGSL shaders + Rust FFI) and CPU implementations, replacing direct CUDA kernel calls - Background compute thread in
MultibeamSonarSensorwith snapshot-based decoupling from the render thread, plus consistent timestamping for ROS messages - Build system migrated from CUDA to a Rust-based
wgpu_vendorpackage with CMake integration, and runtime backend selection via launch arguments
Reviewed changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
multibeam_sonar/sonar_compute_backend.hh |
New abstract backend interface and data structures |
multibeam_sonar/sonar_compute_cpu.cc |
CPU backend implementation and backend factory |
multibeam_sonar/sonar_compute_wgpu.cc/hh |
WGPU backend: C++ wrapper calling Rust FFI with CPU fallback |
multibeam_sonar/MultibeamSonarSensor.cc/hh |
Background compute thread, snapshot-based pipeline, backend integration |
multibeam_sonar/CMakeLists.txt |
Removed CUDA, added wgpu_vendor dependency |
wgpu_vendor/sonar_wgpu_rust/src/lib.rs |
Rust FFI entry point: GPU dispatch, staging readback, CPU FFT fallback |
wgpu_vendor/sonar_wgpu_rust/src/pipeline.rs |
GPU context singleton: device init, buffer management, pipeline compilation |
wgpu_vendor/sonar_wgpu_rust/src/fft.rs |
CPU FFT (Cooley-Tukey + Bluestein) |
wgpu_vendor/sonar_wgpu_rust/src/shaders/*.wgsl |
WGSL compute shaders: backscatter, convert, matmul, FFT |
wgpu_vendor/CMakeLists.txt |
Rust cargo build integration with CMake |
multibeam_sonar_system/CMakeLists.txt |
Simplified: removed CUDA conditionals |
multibeam_sonar_demo/launch/multibeam_sonar_demo.launch.py |
Added compute_backend launch argument |
multibeam_sonar_demo/scripts/plotdata.py |
Save to file instead of plt.show() |
dave_interfaces/CMakeLists.txt |
Removed gz-cmake3/gz-msgs10 dependencies |
models/.../model.sdf |
Debug comment for non-power-of-2 FFT testing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
gazebo/dave_gz_multibeam_sonar/wgpu_vendor/sonar_wgpu_rust/src/lib.rs
Outdated
Show resolved
Hide resolved
gazebo/dave_gz_multibeam_sonar/wgpu_vendor/sonar_wgpu_rust/src/lib.rs
Outdated
Show resolved
Hide resolved
gazebo/dave_gz_multibeam_sonar/wgpu_vendor/sonar_wgpu_rust/src/lib.rs
Outdated
Show resolved
Hide resolved
gazebo/dave_gz_multibeam_sonar/wgpu_vendor/sonar_wgpu_rust/src/pipeline.rs
Outdated
Show resolved
Hide resolved
gazebo/dave_gz_multibeam_sonar/wgpu_vendor/sonar_wgpu_rust/src/fft.rs
Outdated
Show resolved
Hide resolved
gazebo/dave_gz_multibeam_sonar/multibeam_sonar/sonar_compute_wgpu.cc
Outdated
Show resolved
Hide resolved
gazebo/dave_gz_multibeam_sonar/wgpu_vendor/sonar_wgpu_rust/src/shaders/matmul.wgsl
Outdated
Show resolved
Hide resolved
arjo129
reviewed
Mar 17, 2026
gazebo/dave_gz_multibeam_sonar/wgpu_vendor/sonar_wgpu_rust/src/pipeline.rs
Outdated
Show resolved
Hide resolved
gazebo/dave_gz_multibeam_sonar/wgpu_vendor/sonar_wgpu_rust/src/fft.rs
Outdated
Show resolved
Hide resolved
Signed-off-by: Naitik Pahwa <naitikpahwa11@gmail.com>
for more information, see https://pre-commit.ci
Signed-off-by: Naitik Pahwa <naitikpahwa11@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR removes the CUDA dependency from the multibeam sonar implementation and introduces a modular compute backend architecture. A new WGPU-based compute backend is added along with a CPU reference backend used as a fallback when GPU execution is unavailable.
The sonar sensor was refactored to use this backend interface instead of calling CUDA kernels directly. The WGPU implementation runs the sonar compute stages on the GPU using WGSL shaders, while the CPU implementation preserves the existing physics model for deterministic results.
The build system was updated to remove CUDA requirements and integrate a Rust-based WGPU vendor package. Runtime backend selection is also supported.
Validation
The WGPU backend has been tested on Vulkan; support for Metal and DirectX backends is expected via WGPU but remains untested.